using System;
using System.Net;
using System.IO;

public static class BrandService
{
    public static void QueryBrands(string baseUrl, string appkey, string token, string name = "")
    {
        // 构造请求URL
        string url = $"{baseUrl.Trim()}/supplier-openapi/brand/query.lf?appkey={Uri.EscapeDataString(appkey)}&token={Uri.EscapeDataString(token)}";
        if (!string.IsNullOrEmpty(name))
        {
            url += $"&name={Uri.EscapeDataString(name)}";
        }

        // 创建HttpWebRequest对象
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Method = "GET";

        // 发送请求并获取响应
        try
        {
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                string result = reader.ReadToEnd();
                // 打印商品品牌查询结果
                Console.WriteLine("商品品牌查询结果返回：");
                Console.WriteLine(result);
            }
        }
        catch (WebException e)
        {
            Console.WriteLine("发生错误：");
            Console.WriteLine(e.Message);
        }
    }
}
